﻿module Sustainalytics.Governance {
    export class GovernanceCompanyProfileService implements IGovernanceCompanyProfileService {
        constructor(
            private $http: ng.IHttpService,
            private $location: ng.ILocationService,
            private $q:ng.IQService
            ) {
        }


        public getCompanyCgIssuesIndicatorsScoreAndAssesment(companyId: string, issueId: string): ng.IPromise<Sustainalytics.Governance.IndicatorDataIssue[]> {
            var ctx = this;
            var url = ctx.$location.protocol() + "://" + ctx.$location.host() + ":" + ctx.$location.port() + "/governanceserv/api/v1/company/" + companyId + "/cgissues/" + issueId + "/indicators/scoresandasseement";
            var def = ctx.$q.defer();
            var promise = ctx.$http.get(url, { });
            promise.success((data) => { def.resolve(data); }).error((data, status, headers, config) => { def.reject({ data: data, status: status, headers: headers, config: config }); });
            return def.promise;
        }

        public getCompanyRelativePerformance(companyId: string): ng.IPromise<Sustainalytics.Governance.GovernanceRelativePerformanceDto> {
            var ctx = this;
            var url = ctx.$location.protocol() + "://" + ctx.$location.host() + ":" + ctx.$location.port() + "/governanceserv/api/v1/company/" + companyId + "/relativePerformance?details=false";
            var def = ctx.$q.defer();
            var promise = ctx.$http.get(url, {});
            promise.success((data) => { def.resolve(data); }).error((data, status, headers, config) => { def.reject({ data: data, status: status, headers: headers, config: config }); });
            return def.promise;
        }

        public getCompanyRelativePerformanceDetails(companyId: string): ng.IPromise<Sustainalytics.Governance.GovernanceRelativePerformanceDetailsDto> {
            var ctx = this;
            var url = ctx.$location.protocol() + "://" + ctx.$location.host() + ":" + ctx.$location.port() + "/governanceserv/api/v1/company/" + companyId + "/relativePerformance?details=true";
            var def = ctx.$q.defer();
            var promise = ctx.$http.get(url, {});
            promise.success((data) => { def.resolve(data); }).error((data, status, headers, config) => { def.reject({ data: data, status: status, headers: headers, config: config }); });
            return def.promise;
        }

        public getKeyCgIssueTemplate(): ng.IPromise<Sustainalytics.Governance.KeyCGIssueTemplateDto[]> {
            var ctx = this;
            var url = ctx.$location.protocol() + "://" + ctx.$location.host() + ":" + ctx.$location.port() + "/governanceserv/api/v1/keycgtemplate";
            var def = ctx.$q.defer();
            var promise = ctx.$http.get(url, {});
            promise.success((data) => { def.resolve(data); }).error((data, status, headers, config) => { def.reject({ data: data, status: status, headers: headers, config: config }); });
            return def.promise;
        }


        public getCompanyCgIssues(companyId: string): ng.IPromise<Sustainalytics.Governance.CompanyKeyGovernanceIssueDto[]> {
            var ctx = this;
            var url = ctx.$location.protocol() + "://" + ctx.$location.host() + ":" + ctx.$location.port() + "/governanceserv/api/v1/company/" + companyId + "/cgissues?overallScores=false";
            var def = ctx.$q.defer();
            var promise = ctx.$http.get(url, {});
            promise.success((data) => { def.resolve(data); }).error((data, status, headers, config) => { def.reject({ data: data, status: status, headers: headers, config: config }); });
            return def.promise;
        }



        public getCompanyCgIssuesOverallScores(companyId: string): ng.IPromise<Sustainalytics.Governance.CompanyKeyGovernanceIssueOveralScoresDto> {
            var ctx = this;
            var url = ctx.$location.protocol() + "://" + ctx.$location.host() + ":" + ctx.$location.port() + "/governanceserv/api/v1/company/" + companyId + "/cgissues?overallScores=true";
            var def = ctx.$q.defer();
            var promise = ctx.$http.get(url, {});
            promise.success((data) => { def.resolve(data); }).error((data, status, headers, config) => { def.reject({ data: data, status: status, headers: headers, config: config }); });
            return def.promise;
        }

        public getCompanyCgIssuesIndicators(companyId: string, issueId: string): ng.IPromise<Sustainalytics.Governance.CompanyGovernanceIssueDto> {
            var ctx = this;
            var url = ctx.$location.protocol() + "://" + ctx.$location.host() + ":" + ctx.$location.port() + "/governanceserv/api/v1/company/" + companyId + "/cgissues/" + issueId + "/indicators";
            var def = ctx.$q.defer();
            var promise = ctx.$http.get(url, {});
            promise.success((data) => { def.resolve(data); }).error((data, status, headers, config) => { def.reject({ data: data, status: status, headers: headers, config: config }); });
            return def.promise;
        }
        public getCompanyCgOverallPerformance(companyId: string): ng.IPromise<Sustainalytics.Governance.GovernanceCompanyOverallDto> {
            var ctx = this;
            var url = ctx.$location.protocol() + "://" + ctx.$location.host() + ":" + ctx.$location.port() + "/governanceserv/api/v1/company/" + companyId + "/overallPerformance";
            var def = ctx.$q.defer();
            var promise = ctx.$http.get(url, {});
            promise.success((data) => { def.resolve(data); }).error((data, status, headers, config) => { def.reject({ data: data, status: status, headers: headers, config: config }); });
            return def.promise;
        }

      
       

    }
    
    angular.module(governanceModuleName).service('GovernanceCompanyProfileService', ['$http', '$location', '$q', GovernanceCompanyProfileService]);
} 